package com.cws4cloud.cws.mall.cms.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cws4cloud.cws.common.core.constant.BaseSQLConf;
import com.cws4cloud.cws.common.core.constant.CommonConstants;
import com.cws4cloud.cws.common.core.constant.enums.StatusEnum;
import com.cws4cloud.cws.mall.cms.entity.News;
import com.cws4cloud.cws.mall.cms.mapper.NewsMapper;
import com.cws4cloud.cws.mall.cms.service.NewsService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 内容管理
 *
 * @author zhulj
 * @date 2021-04-20 17:21:31
 */
@Service
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements NewsService {

	@Override
	public List<Map<String, Object>> getNewsCountGroupByClass(Integer siteId) {
		return baseMapper.getNewsCountGroupByClass(siteId);
	}

	@Override
	public IPage<News> getHotNews(Integer classlistId, Integer siteId) {
		QueryWrapper<News> queryWrapper = new QueryWrapper<>();
		Page<News> page = new Page<>();
		queryWrapper.eq(BaseSQLConf.HOT, CommonConstants.YES);
		queryWrapper.eq(BaseSQLConf.STATUS, StatusEnum.SHOW);
		queryWrapper.eq(BaseSQLConf.SITE_ID, siteId);
		queryWrapper.eq(classlistId!=null, "classlist_id", classlistId);
		return baseMapper.selectPage(page,queryWrapper);
	}

	@Override
	public IPage<News> getNewsByClasslistId(Integer classlistId, Integer siteId) {
		QueryWrapper<News> queryWrapper = new QueryWrapper<>();
		Page<News> page = new Page<>();
		queryWrapper.eq(BaseSQLConf.STATUS, StatusEnum.SHOW);
		queryWrapper.eq(BaseSQLConf.SITE_ID, siteId);
		queryWrapper.eq("classlist_id", classlistId);
		return baseMapper.selectPage(page,queryWrapper);
	}

	@Override
	public News getPreNews(Integer classId, Integer sequence) {
		return baseMapper.getPreNews(classId, sequence);
	}

	@Override
	public News getNextNews(Integer classId, Integer sequence) {
		return baseMapper.getNextNews(classId, sequence);
	}
}
